//
//  VRLiveRoomView.swift
//  VoiceRoom
//
//  Created by Rui on 2024/3/30.
//

import UIKit

class VRLiveRoomTopView: UIView {

    private let closeButton          = c_make_ex(UIButton.self)
        .image("LiveRoom_close").end()
    private let personView          = c_make_ex(UIView.self)
        .bgColor(.white.alpha(0.1)).corner(22).end()
    private let iconImageView = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).corner(15).bgColor(.red).end()
    private let addButton          = c_make_ex(UIButton.self)
        .image("LiveRoom_add").end()
    private let nameLabel          = c_make_ex(UILabel.self)
        .font(16.font_bold).color(.white).text("Justali").end()
    private let idLabel          = c_make_ex(UILabel.self)
        .font(12.font_medium).color(.white.alpha(0.4)).text("ID: 89794466").end()
    
    var closeBlock: (() -> Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        subviews{
            closeButton
            personView.subviews{
                iconImageView
                addButton
                nameLabel
                idLabel
            }
        }
        
        closeButton.top(2).trailing(5).size(40)
        personView.leading(15).top(0).height(44).width(170)
        iconImageView.leading(8).top(7).size(30)
        addButton.trailing(0).top(2).size(40)
        nameLabel.leading(45).top(4)
        nameLabel.Trailing == addButton.Leading - 10
        idLabel.leading(45).bottom(4)
        idLabel.Trailing == addButton.Leading
        
        personView.isUserInteractionEnabled = true
        
        closeButton.addTarget(self, action: #selector(clickCloseButton), for: .touchUpInside)
    }
    
    @objc private func clickCloseButton(){
        closeBlock?()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

class VRLiveRoomBottomView: UIView {

    private let giftButton          = c_make_ex(UIButton.self)
        .image("LiveRoom_gift").end()
    private let sofaButton = UIIconButton(style: .leading(itemSpace: 0))
    private let menuButton          = c_make_ex(UIButton.self)
        .image("LiveRoom_menu").end()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        subviews{
            giftButton
            sofaButton
            menuButton
        }
        
        giftButton.trailing(15).top(5).size(44)
        sofaButton.top(5).height(44).width(85).trailing(70)
        menuButton.size(44).top(5).leading(110)
        
        sofaButton.style { v in
            v.setImage("LiveRoom_sofa".toImage, for: .normal)
            v.iconSize = CGSizeMake(44, 44)
            v.setTitleColor("#FFFC00".toColor, for: .normal)
            v.setTitle("Jion", for: .normal)
            v.titleLabel?.font = 14.font_semiBold
            v.addTarget(self, action: #selector(joinButton), for: .touchUpInside)
        }
    }
    
    @objc private func joinButton(){
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}


class VRLiveRoomBottomChatView: UIView {

    lazy var commitView: FJChatTextView = {
        let view = FJChatTextView()
        view.backgroundColor = .white.alpha(0.1)
        view.textContainerInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
        view.tintColor = .white
        view.textColor = .white
        view.placeHolderColor = .white.alpha(0.4)
        view.placeHolder = "Say something…"
        view.placeholderFont = 14.font_medium
        view.returnKeyType = .done
        view.font = 14.font_medium
        view.layer.cornerRadius = 20
        view.layer.masksToBounds = true
        return view
    }()
    private let sendButton = c_make_ex(UIButton.self)
        .image("LiveRoom_send".toImage).end()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = "#1E1D24".toColor
        
        subviews{
            commitView
            sendButton
        }
        
        sendButton.trailing(10).top(10).bottom(10).size(40)
        commitView.leading(10).height(40).top(10).bottom(10)
        commitView.Trailing == sendButton.Leading - 10
    }
    
    @objc private func joinButton(){
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
